//
//  ListTableViewCell.m
//  UI-21-豆豆豆瓣
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 Wang Hao. All rights reserved.
//

#import "ListTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation ListTableViewCell

- (void)dealloc
{
    [_movie release];
    [_headImageView release];
    [_nameLabel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        
        [self create];
    }
    return  self;
    
}

-(void)create{
    
    //大图片
    UIImageView *bigView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_eventlistcell"]];
    bigView.frame = CGRectMake(10, 10, 375-20, 140);
    [self.contentView addSubview:bigView];
    [bigView release];
    
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 140/2-20, 200, 40)];
    self.nameLabel.text = @"";
    [bigView addSubview:self.nameLabel];
    [_nameLabel release];
    
    self.headImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    self.headImageView.frame = CGRectMake(10, 5, 85, 130);
    self.headImageView.backgroundColor = [UIColor yellowColor];
    [bigView addSubview:self.headImageView];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(300, 10, 30, 30);
    [self.button setBackgroundImage:[UIImage imageNamed:@"check@2x"] forState:UIControlStateNormal];
    
    
    [self.button addTarget:self action:@selector(butAction:) forControlEvents:UIControlEventTouchUpInside];
    [bigView addSubview:self.button];
    bigView.userInteractionEnabled = YES;
    
    //设置半径
    //self.headImageView.layer.cornerRadius = 10;
    //设置边框
    //self.headImageView.layer.borderWidth = 3;
    //设置边框颜色
    //self.headImageView.layer.borderColor = [UIColor redColor].CGColor;
    [_headImageView release];
    
}

-(void)butAction:(UIButton *)but{
    
    if (self.movie.isSelect){
    [self.button setBackgroundImage:[UIImage imageNamed:@"checked@2x"] forState:UIControlStateNormal];
    }else{
        
    [self.button setBackgroundImage:[UIImage imageNamed:@"check@2x"] forState:UIControlStateNormal];
    }
    self.movie.isSelect = !self.movie.isSelect;
    [self.listDelegate sentModel:self.movie];
    
}

-(void)setMovie:(Movie *)movie{
    
    if (_movie != movie) {
        [_movie release];
        _movie = [movie retain];
    }
    
    self.nameLabel.text = self.movie.movieName;
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:self.movie.pic_url] placeholderImage:[UIImage imageNamed:@"movie"]];
    
    
    if (movie.isSelect == YES){
        [self.button setBackgroundImage:[UIImage imageNamed:@"check@2x"] forState:UIControlStateNormal];
    }else{
       [self.button setBackgroundImage:[UIImage imageNamed:@"checked@2x"] forState:UIControlStateNormal];
    }
}


    
    








- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
